package cn.itrip.biz.service.itripAreaDic;
import cn.itrip.mapper.ItripAreaDic.ItripAreaDicMapper;
import cn.itrip.pojo.ItripAreaDic;
import cn.itrip.common.*;
import cn.itrip.vo.ItripAreaDicVO;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import cn.itrip.common.Constants;
@Service
public class ItripAreaDicServiceImpl implements ItripAreaDicService {

    @Resource
    private ItripAreaDicMapper itripAreaDicMapper;

    public ItripAreaDic getItripAreaDicById(Long id)throws Exception{
        return itripAreaDicMapper.getItripAreaDicById(id);
    }

    /**
     * 查询国内外酒店
     * @param type
     * @return
     * @throws Exception
     */
    @Override
    public List<ItripAreaDicVO> getItripAreaDicByIsChina(Integer type) throws Exception {
        List<ItripAreaDicVO> itripAreaDicVO = new ArrayList<>();
        List<ItripAreaDic> itripAreaDicByIsChina = itripAreaDicMapper.getItripAreaDicByIsChina(type);
        for (ItripAreaDic itripAreaDic : itripAreaDicByIsChina) {
            ItripAreaDicVO vo=new ItripAreaDicVO();
            vo.setId(itripAreaDic.getId());
            vo.setName(itripAreaDic.getName());
            itripAreaDicVO.add(vo);
        }
        return itripAreaDicVO;
    }

    @Override
    public List<ItripAreaDicVO> queryTradingAreaNameList(Integer cityId) {
        return itripAreaDicMapper.queryTradingAreaNameList(cityId);
    }

    @Override
    public List<String> queryIdAreaNameList(Integer cityId) {
        return itripAreaDicMapper.queryIdAreaNameList(cityId);
    }

    @Override
    public List<String> queryFeatureIdList(Integer cityId) {
        return itripAreaDicMapper.queryFeatureIdList(cityId);
    }

    public List<ItripAreaDic>	getItripAreaDicListByMap(Map<String,Object> param)throws Exception{
        return itripAreaDicMapper.getItripAreaDicListByMap(param);
    }

    public Integer getItripAreaDicCountByMap(Map<String,Object> param)throws Exception{
        return itripAreaDicMapper.getItripAreaDicCountByMap(param);
    }

    public Integer itriptxAddItripAreaDic(ItripAreaDic itripAreaDic)throws Exception{
            itripAreaDic.setCreationDate(new Date());
            return itripAreaDicMapper.insertItripAreaDic(itripAreaDic);
    }

    public Integer itriptxModifyItripAreaDic(ItripAreaDic itripAreaDic)throws Exception{
        itripAreaDic.setModifyDate(new Date());
        return itripAreaDicMapper.updateItripAreaDic(itripAreaDic);
    }

    public Integer itriptxDeleteItripAreaDicById(Long id)throws Exception{
        return itripAreaDicMapper.deleteItripAreaDicById(id);
    }

    public Page<ItripAreaDic> queryItripAreaDicPageByMap(Map<String,Object> param,Integer pageNo,Integer pageSize)throws Exception{
        Integer total = itripAreaDicMapper.getItripAreaDicCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<ItripAreaDic> itripAreaDicList = itripAreaDicMapper.getItripAreaDicListByMap(param);
        page.setRows(itripAreaDicList);
        return page;
    }

}
